Skip to content

Conversation

beicause
Copy link
Contributor

Closes #1299.
Adds on_main_loop_startup, on_main_loop_frame, on_main_loop_shutdown callbacks to ExtensionLibrary for Godot 4.5.

This PR needs rebase once we have api-4.5 feature.

@Bromeon Bromeon added feature Adds functionality to the library c: ffi Low-level components and interaction with GDExtension API labels Sep 16, 2025
@Bromeon Bromeon added this to the 0.4.x milestone Sep 16, 2025
@beicause beicause force-pushed the main-loop-callbacks branch from 66e5afc to 5daf025 Compare October 7, 2025 14:01
@beicause beicause marked this pull request as ready for review October 7, 2025 14:06
@GodotRust
Copy link

API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-1313

Copy link
Member

@Bromeon Bromeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update!

@beicause beicause force-pushed the main-loop-callbacks branch 2 times, most recently from 5cbea37 to a012d2f Compare October 7, 2025 15:21
Copy link
Member

@Bromeon Bromeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Some thoughts:

  • Godot uses "startup" and "shutdown", I think we should keep things consistent with the other godot-rust APIs and use "init" and "deinit" instead. Then we'd have on_level_init + on_main_loop_init, etc.
  • Is there a strict order between the levels and the main loop? If yes, should we (not in this PR, but a follow-up) consider representing MainLoop as its own InitLevel?

@beicause
Copy link
Contributor Author

beicause commented Oct 8, 2025

  • Godot uses "startup" and "shutdown", I think we should keep things consistent with the other godot-rust APIs and use "init" and "deinit" instead. Then we'd have on_level_init + on_main_loop_init, etc.
  • Is there a strict order between the levels and the main loop? If yes, should we (not in this PR, but a follow-up) consider representing MainLoop as its own InitLevel?

on_main_loop_init feels off, the startup is actually after the MainLoop/SceneTree is created. It is the final step of Main::start() and after all init levels (shutdown is the vice versa, before all init levels).

I think it's better to make them separate functions, keeping on_init_level lean so you're less likely to make mistakes in it.

@beicause beicause force-pushed the main-loop-callbacks branch from a012d2f to 663535e Compare October 8, 2025 04:44
@Bromeon
Copy link
Member

Bromeon commented Oct 12, 2025

on_main_loop_init feels off, the startup is actually after the MainLoop/SceneTree is created. It is the final step of Main::start() and after all init levels (shutdown is the vice versa, before all init levels).

So there is a clear order: all levels -> main loop (init).

In my opinion, it's much easier to understand this by having a separate level, as there is only one API rather than "normal init levels + out-of-band main loop that just happens to be another level". We should see this from user perspective, not from the API that GDExtension itself provides us with. But I can address this later.

Thanks a lot!

@Bromeon Bromeon added this pull request to the merge queue Oct 12, 2025
@Bromeon Bromeon removed this pull request from the merge queue due to a manual request Oct 12, 2025
@Bromeon Bromeon added this pull request to the merge queue Oct 12, 2025
Merged via the queue into godot-rust:master with commit 3db89e8 Oct 12, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: ffi Low-level components and interaction with GDExtension API feature Adds functionality to the library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support registering main loop callback in Godot 4.5

3 participants